/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.ces4.produccion.jpa.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PostLoad;
import javax.persistence.Table;

/**
 *
 * @author usuario
 */
@Entity
@Table(name = "tpdr_usuario")
@NamedQueries({
    @NamedQuery(name = "Usuario.findAll", query = "SELECT u FROM Usuario u")})
public class Usuario implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "DSID", nullable = false, length = 20)
    private String dsid;
    @Basic(optional = false)
    @Column(name = "DSNOMBRE", nullable = false, length = 50)
    private String dsnombre;
    @Basic(optional = false)
    @Column(name = "DSAPELLIDO1", nullable = false, length = 20)
    private String dsapellido1;
    @Column(name = "DSAPELLIDO2", length = 20)
    private String dsapellido2;
    @Basic(optional = false)
    @Column(name = "SNESTADO", nullable = false)
    private boolean snestado;
    @Basic(optional = false)
    @Column(name = "DSUSUARIO", nullable = false, length = 150)
    private String dsusuario;
    @Basic(optional = false)
    @Column(name = "DSPASSWORD", nullable = false, length = 30)
    private String dspassword;
    @JoinTable(name = "tpdr_usuario_perfil", joinColumns = {
        @JoinColumn(name = "DSUSUARIO", referencedColumnName = "DSID", nullable = false)}, inverseJoinColumns = {
        @JoinColumn(name = "NMPERFIL", referencedColumnName = "NMID", nullable = false)})
    @ManyToMany(fetch = FetchType.LAZY)
    private List<Perfil> perfilList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "dsusuario", fetch = FetchType.LAZY)
    private List<OrdenProduccion> ordenProduccionList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "dsusuario", fetch = FetchType.LAZY)
    private List<SolicitudProduccion> solicitudProduccionList;

    public Usuario() {
    }

    public Usuario(String dsid) {
        this.dsid = dsid;
    }

    public Usuario(String dsid, String dsnombre, String dsapellido1, boolean snestado) {
        this.dsid = dsid;
        this.dsnombre = dsnombre;
        this.dsapellido1 = dsapellido1;
        this.snestado = snestado;
    }

    public String getDsid() {
        return dsid;
    }

    public void setDsid(String dsid) {
        this.dsid = dsid;
    }

    public String getDsnombre() {
        return dsnombre;
    }

    public void setDsnombre(String dsnombre) {
        this.dsnombre = dsnombre;
    }

    public String getDsapellido1() {
        return dsapellido1;
    }

    public void setDsapellido1(String dsapellido1) {
        this.dsapellido1 = dsapellido1;
    }

    public String getDsapellido2() {
        return dsapellido2;
    }

    public void setDsapellido2(String dsapellido2) {
        this.dsapellido2 = dsapellido2;
    }

    public boolean getSnestado() {
        return snestado;
    }

    public void setSnestado(boolean snestado) {
        this.snestado = snestado;
    }

    public String getDsusuario() {
        return dsusuario;
    }

    public void setDsusuario(String dsusuario) {
        this.dsusuario = dsusuario;
    }

    public String getDspassword() {
        return dspassword;
    }

    public void setDspassword(String dspassword) {
        this.dspassword = dspassword;
    }

    public List<Perfil> getPerfilList() {
        return perfilList;
    }

    public void setPerfilList(List<Perfil> perfilList) {
        this.perfilList = perfilList;
    }

    public List<OrdenProduccion> getOrdenProduccionList() {
        return ordenProduccionList;
    }

    public void setOrdenProduccionList(List<OrdenProduccion> ordenProduccionList) {
        this.ordenProduccionList = ordenProduccionList;
    }

    public List<SolicitudProduccion> getSolicitudProduccionList() {
        return solicitudProduccionList;
    }

    public void setSolicitudProduccionList(List<SolicitudProduccion> solicitudProduccionList) {
        this.solicitudProduccionList = solicitudProduccionList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (dsid != null ? dsid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usuario)) {
            return false;
        }
        Usuario other = (Usuario) object;
        if ((this.dsid == null && other.dsid != null) || (this.dsid != null && !this.dsid.equals(other.dsid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.com.ces4.produccion.jpa.entities.Usuario[ dsid=" + dsid + " ]";
    }

    @PostLoad
    public void fixIt() {
        this.perfilList = new ArrayList<Perfil>(this.perfilList);
        this.ordenProduccionList = new ArrayList<OrdenProduccion>(this.ordenProduccionList);
        this.solicitudProduccionList = new ArrayList<SolicitudProduccion>(this.solicitudProduccionList);
    }
}
